﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace GSLMS.Entity.Model
{
    /// <summary>
    /// 2.3.93	总裁/董事长审批提出的方案信息表
    /// </summary>
    [DataContract(IsReference = true)]
    public partial class TB_APP_GENERALAUDITPROGRAM : IObjectWithChangeTracker, INotifyPropertyChanged
    {

        #region Model
        private long _id;
        private long _proid;
        private long _generalauditID;
        private int _progno;
        private string _progcat;
        private decimal _amt;
        private decimal _rate;
        private decimal _managerate;
        private decimal _generalrate;
        private int _loantime;
        private int _loanphase;
        private int _loanphasetype;
        private decimal _advamt;
        private string _auditremark;
        /// <summary>
        /// 记录ID唯一
        /// </summary>
        [DataMember]
        public long ID
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    if (ChangeTracker.ChangeTrackingEnabled && ChangeTracker.State != ObjectState.Added)
                    {
                        throw new InvalidOperationException("属性“ID”是对象键的一部分，不可更改。仅当未跟踪对象或对象处于“已添加”状态时，才能对键属性进行更改。");
                    }
                    _id = value;
                    OnPropertyChanged("ID");
                }
            }
        }
        /// <summary>
        /// 立项申请记录IDTb_app_proinfo.id
        /// </summary>
        [DataMember]
        public long PROID
        {
            get { return _proid; }
            set
            {
                if (_proid != value)
                {
                    _proid = value;
                    OnPropertyChanged("PROID");
                }
            }
        }
        /// <summary>
        /// 总裁、董事长审批记录ID
        /// </summary>
        [DataMember]
        public long GENERALAUDITID
        {
            get { return _generalauditID; }
            set
            {
                if (_generalauditID != value)
                {
                    _generalauditID = value;
                    OnPropertyChanged("GENERALAUDITID");
                }
            }
        }
        /// <summary>
        /// 序号
        /// </summary>
        [DataMember]
        public int PROGNO
        {
            get { return _progno; }
            set
            {
                if (_progno != value)
                {
                    _progno = value;
                    OnPropertyChanged("PROGNO");
                }
            }
        }
        /// <summary>
        /// 类型
        /// </summary>
        [DataMember]
        public string PROGCAT
        {
            get { return _progcat; }
            set
            {
                if (_progcat != value)
                {
                    _progcat = value;
                    OnPropertyChanged("PROGCAT");
                }
            }
        }
        /// <summary>
        /// 批核金额
        /// </summary>
        [DataMember]
        public decimal AMT
        {
            get { return _amt; }
            set
            {
                if (_amt != value)
                {
                    _amt = value;
                    OnPropertyChanged("AMT");
                }
            }
        }
        /// <summary>
        /// 贷款利率
        /// </summary>
        [DataMember]
        public decimal RATE
        {
            get { return _rate; }
            set
            {
                if (_rate != value)
                {
                    _rate = value;
                    OnPropertyChanged("RATE");
                }
            }
        }
        /// <summary>
        /// 管理费率
        /// </summary>
        [DataMember]
        public decimal MANAGERATE
        {
            get { return _managerate; }
            set
            {
                if (_managerate != value)
                {
                    _managerate = value;
                    OnPropertyChanged("MANAGERATE");
                }
            }
        }
        /// <summary>
        /// 综合费率
        /// </summary>
        [DataMember]
        public decimal GENERALRATE
        {
            get { return _generalrate; }
            set
            {
                if (_generalrate != value)
                {
                    _generalrate = value;
                    OnPropertyChanged("GENERALRATE");
                }
            }
        }
        /// <summary>
        /// 期限
        /// </summary>
        [DataMember]
        public int LOANTIME
        {
            get { return _loantime; }
            set
            {
                if (_loantime != value)
                {
                    _loantime = value;
                    OnPropertyChanged("LOANTIME");
                }
            }
        }
        /// <summary>
        /// 期限类型
        /// </summary>
        [DataMember]
        public int LOANPHASE
        {
            get { return _loanphase; }
            set
            {
                if (_loanphase != value)
                {
                    _loanphase = value;
                    OnPropertyChanged("LOANPHASE");
                }
            }
        }
        /// <summary>
        /// 还款方式具体参考” 还款计息方式”文档
        /// </summary>
        [DataMember]
        public int LOANPHASETYPE
        {
            get { return _loanphasetype; }
            set
            {
                if (_loanphasetype != value)
                {
                    _loanphasetype = value;
                    OnPropertyChanged("LOANPHASETYPE");
                }
            }
        }
        /// <summary>
        /// 预收费用
        /// </summary>
        [DataMember]
        public decimal ADVAMT
        {
            get { return _advamt; }
            set
            {
                if (_advamt != value)
                {
                    _advamt = value;
                    OnPropertyChanged("ADVAMT");
                }
            }
        }
        /// <summary>
        /// 批核备注
        /// </summary>
        [DataMember]
        public string AUDITREMARK
        {
            get { return _auditremark; }
            set
            {
                if (_auditremark != value)
                {
                    _auditremark = value;
                    OnPropertyChanged("AUDITREMARK");
                }
            }
        }
        #endregion Model

        #region ChangeTracking

        protected virtual void OnPropertyChanged(String propertyName)
        {
            if (ChangeTracker.State != ObjectState.Added && ChangeTracker.State != ObjectState.Deleted)
            {
                ChangeTracker.State = ObjectState.Modified;
            }
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected virtual void OnNavigationPropertyChanged(String propertyName)
        {
            if (_propertyChanged != null)
            {
                _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
        private event PropertyChangedEventHandler _propertyChanged;
        private ObjectChangeTracker _changeTracker;

        [DataMember]
        public ObjectChangeTracker ChangeTracker
        {
            get
            {
                if (_changeTracker == null)
                {
                    _changeTracker = new ObjectChangeTracker();
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
                return _changeTracker;
            }
            set
            {
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
                }
                _changeTracker = value;
                if (_changeTracker != null)
                {
                    _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
                }
            }
        }

        private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
        {
            if (e.NewState == ObjectState.Deleted)
            {
                ClearNavigationProperties();
            }
        }

        protected bool IsDeserializing { get; private set; }

        [OnDeserializing]
        public void OnDeserializingMethod(StreamingContext context)
        {
            IsDeserializing = true;
        }

        [OnDeserialized]
        public void OnDeserializedMethod(StreamingContext context)
        {
            IsDeserializing = false;
            ChangeTracker.ChangeTrackingEnabled = true;
        }

        protected virtual void ClearNavigationProperties()
        {
        }

        #endregion
    }
}
